
#include "uart.h"
#include "flash.h"
#include "xn297l.h"
#include "contralswitch.h"
void init(void)
{
    CLK_DeInit();
    // 内部16M时钟
    CLK_HSICmd(ENABLE);
    // 默认为8分频，这里改成不分频
    CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
    myUartInit();

    spiInit();
    initFlash();
    memcpy(pXn297l->address, pFlashData->address, 5);
    pXn297l->address[0] = 56;
    pXn297l->channel = (pXn297l->address[0] % 60);
    pXn297l->check();
    if (pXn297l->status == SELF_OK)
    {
        pXn297l->init();
        // pXn297l->connect();
        sendData(pXn297l->address, sizeof(pXn297l->address));
    }
}


//tx
int main()
{
    init();
    xn297lWriteBuf(W_REGISTER + TX_ADDR, tx_address0, sizeof(tx_address0));
    xn297lWriteBuf(W_REGISTER + RX_ADDR_P0,tx_address0, sizeof(tx_address0));
 
    while (1)
    { 
        pXn297l->send();
        
        for (volatile int i = 0; i < 20; i++)
        { 
            delay();
        }  
        switchaddress(1,2);
    }
}

